Cape Cod is home to many different types of places to grab a drink. There are all sorts of bars, pubs, restaurants with bars and so on. Nearly all are open in season typically June-August, many are open for extended periods April-October, for example and fewer are open year round. In the off-season it would be wise to call ahead or go online before making a trip to one of the bars.
The drinking age in Massachusetts is 21 and ID's are rigorously checked on the Cape, especially during the summer tourist season. Bars, clubs and package stores tend to be very wary about serving to patrons with an out of state license or ID, some won't sell to you at all, and others limit non-Massachusetts ID's to certain states usually New Hampshire and/or Rhode Island, restaurants and taverns are typically more lenient. Most establishments that do accept an out of state license will request a second form of ID, such as a passport or school ID. If you'll be in the area for awhile, one way to get around this problem is to obtain a Liquor ID from the Registry of Motor Vehicles. You do not need to be a resident, although a Massachusetts mailing address is required could be that of a friend or relative, along with proof of age and signature. The cost is $25 and the card is valid for five years.